// 连接到UNIX 套接字， 并打印接收到的数据

const net = require('net'), client = new net.Socket();
client.setEncoding('utf8');

const unixSocket = '/home/nodejs/nodesocket';
// connect to server
client.connect(unixSocket, () => {
  console.log('connected to server')
  client.write('Who needs a browser to communicate?');

})

// when receive data, send to server 
process.stdin.on('data', (data) => {
  client.write(data)
})

// when recevie data back, print to console
client.on( 'data', (data) => {
  console.log(data);
}) 
// when server close
client.on('close' , () => {
  console.log('connected is closed');
})
